package cnooc.energy.controller;


import cnooc.common.annotation.Log;
import cnooc.common.core.controller.BaseController;
import cnooc.common.core.domain.AjaxResult;
import cnooc.common.core.page.TableDataInfo;
import cnooc.common.enums.BusinessType;
import cnooc.common.utils.poi.ExcelUtil;
import cnooc.energy.domain.DeviceDataLocation;
import cnooc.energy.service.IDeviceDataLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备点位配置Controller
 * 
 * @author lambda
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/energy/deviceDataLocation")
public class DeviceDataLocationController extends BaseController
{
    @Autowired
    private IDeviceDataLocationService deviceDataLocationService;

    /**
     * 查询设备点位配置列表
     */
    @PreAuthorize("@ss.hasPermi('energy:deviceDataLocation:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceDataLocation deviceDataLocation)
    {
        startPage();
        List<DeviceDataLocation> list = deviceDataLocationService.selectDeviceDataLocationList(deviceDataLocation);
        return getDataTable(list);
    }

    /**
     * 导出设备点位配置列表
     */
    @PreAuthorize("@ss.hasPermi('energy:deviceDataLocation:export')")
    @Log(title = "设备点位配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceDataLocation deviceDataLocation)
    {
        List<DeviceDataLocation> list = deviceDataLocationService.selectDeviceDataLocationList(deviceDataLocation);
        ExcelUtil<DeviceDataLocation> util = new ExcelUtil<DeviceDataLocation>(DeviceDataLocation.class);
        util.exportExcel(response, list, "设备点位配置数据");
    }

    /**
     * 获取设备点位配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('energy:deviceDataLocation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deviceDataLocationService.selectDeviceDataLocationById(id));
    }

    /**
     * 新增设备点位配置
     */
    @PreAuthorize("@ss.hasPermi('energy:deviceDataLocation:add')")
    @Log(title = "设备点位配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceDataLocation deviceDataLocation)
    {
        return toAjax(deviceDataLocationService.insertDeviceDataLocation(deviceDataLocation));
    }

    /**
     * 修改设备点位配置
     */
    @PreAuthorize("@ss.hasPermi('energy:deviceDataLocation:edit')")
    @Log(title = "设备点位配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceDataLocation deviceDataLocation)
    {
        return toAjax(deviceDataLocationService.updateDeviceDataLocation(deviceDataLocation));
    }

    /**
     * 删除设备点位配置
     */
    @PreAuthorize("@ss.hasPermi('energy:deviceDataLocation:remove')")
    @Log(title = "设备点位配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceDataLocationService.deleteDeviceDataLocationByIds(ids));
    }


    @GetMapping("/dataLocationAndNameByDeviceId/{id}/{queryClass}")
    public AjaxResult dataLocationAndNameByDeviceId(@PathVariable Long id,@PathVariable String queryClass) {
        return success(deviceDataLocationService.selectLocationByDeviceId(id,queryClass));
    }

    @GetMapping("/otherLocation/{deviceId}/{selfId}")
    public AjaxResult otherLocation(@PathVariable String deviceId, @PathVariable(required = false) String selfId) {
        return success(deviceDataLocationService.otherLocation(deviceId, selfId));
    }
}
